﻿using ServiceCore.DbContext;
using ServiceCore.Entity.Core;
using ServiceCore.Entity.Model;

namespace ServiceCore.Service
{
    /// <summary>
    /// 数组服务
    /// </summary>
    public partial class SiteService : SqlsugarServices<SiteInfo>
    {
        public BaseParam<SiteInfo, long> Site_Save_Common_Verify(BaseParam<SiteInfo, long> arg)
        {
            if (arg == null)
                return new BaseParam<SiteInfo, long>("参数不能为空");
            if (arg.Param == null)
                return new BaseParam<SiteInfo, long>("参数不能为空");
            if (string.IsNullOrEmpty(arg.Param.Name))
                return new BaseParam<SiteInfo, long>("数组名称不能为空");
            if (arg.Param.CreateUserId == 0)
                return new BaseParam<SiteInfo, long>("创建人不能为空");

            return arg;
        }

        public BaseParam<SiteInfo, long> Site_Add_Verify(BaseParam<SiteInfo, long> arg)
        {
            arg = Site_Save_Common_Verify(arg);
            if (string.IsNullOrEmpty(arg.ErrorMsg) == false)
                return arg;

            var argUser = new BaseParam<SiteInfo, SiteInfo>();
            argUser.Param = arg.Param;
            Site_Exists(argUser, true);
            if (argUser.Data != null)
                return new BaseParam<SiteInfo, long>("数组名称已存在");

            arg.Param.CreateTime = DateTime.Now;
            return arg;
        }

        public BaseParam<SiteInfo, long> Site_Edit_Verify(BaseParam<SiteInfo, long> arg)
        {
            arg = Site_Save_Common_Verify(arg);
            if (string.IsNullOrEmpty(arg.ErrorMsg) == false)
                return arg;
            if (arg.Param.Id == 0)
                return new BaseParam<SiteInfo, long>("id不能为空");

            var argUser = new BaseParam<SiteInfo, SiteInfo>();
            argUser.Param = arg.Param;
            Site_Exists(argUser, false);
            if (argUser.Data != null)
                return new BaseParam<SiteInfo, long>("数组名称已存在");

            return arg;
        }

        public BaseParam<SiteInfo, long> Site_Del_Verify(BaseParam<SiteInfo, long> arg)
        {
            if (arg == null)
                return new BaseParam<SiteInfo, long>("参数不能为空");
            if (arg.Id == 0)
                return new BaseParam<SiteInfo, long>("id不能为空");

            return arg;
        }
    }
}
